import scrapy


# 进行设置，设置完成后进行怕从的编写

class ShuangseqiuSpider(scrapy.Spider):
    name = "shuangseqiu"  # 爬虫名称
    allowed_domains = ["sina.com.cn"]
    start_urls = ["https://view.lottery.sina.com.cn/lotto/pc_zst/index?lottoType=ssq&actionType=chzs&type=50&dpc=1"]

    def parse(self, resp, **kwargs):
        # 先打印数据看是否存在需要回去的数据
        # 获取需要获取的内容
        trs = resp.xpath('//*[@id="cpdata"]/tr')
        i = 0
        for tr in trs:
            i += 1
            timer = tr.xpath('./td/text()').extract_first()
            hong = tr.xpath('./td[@class="chartball01" or @class="chartball20"]/text()').extract()
            lan = tr.xpath('./td[@class="chartball02"]/text()').extract_first()
            yield {
                "i": i,
                "timer": timer,
                "hong": "_".join(hong),
                "lan": lan
            }
